import 'package:xinxuan/vo/common_vo/common_address_item_vo.dart';
import 'package:xinxuan/vo/common_vo/common_costs_vo.dart';

class OrderDetailVo {
  OrderDetailData? data;

  OrderDetailVo({this.data});

  OrderDetailVo.fromJson(Map<String, dynamic> json) {
    data = json['data'] != null ? new OrderDetailData.fromJson(json['data']) : null;
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    if (this.data != null) {
      data['data'] = this.data!.toJson();
    }
    return data;
  }
}

class OrderDetailData {
  int? id;
  String? orderSn;
  int? status;
  int? paymentType;
  int? payStatus;
  dynamic paidAmount;
  String? payableAmount;
  dynamic totalAmount;
  int? integral;
  String? trackingNumber;
  String? createdAt;
  int? remainingTime;
  int? isCheck;
  String? statusStr;
  String? companyTitle;
  String? companyCode;
  int? pickType;
  String? voucherCode;
  String? writeoffUrl;
  int? transferRemaining;
  String? tips;
  String? tips2;
  int? type;
  int? isTransfer;

  List<OrderProductsItem>? products;
  CommonAddressItem? address;
  List<CommonCostsVo>? costs;
  List<Transfer>? transfer;

  OrderDetailData(
      {this.id,
      this.orderSn,
      this.status,
      this.companyTitle,
      this.paymentType,
      this.payStatus,
      this.paidAmount,
      this.payableAmount,
      this.totalAmount,
      this.integral,
      this.trackingNumber,
      this.createdAt,
      this.remainingTime,
      this.products,
      this.address,
      this.costs,
      this.isCheck,
      this.statusStr,
      this.companyCode,
      this.pickType,
      this.voucherCode,
      this.writeoffUrl,
      this.transfer,
      this.transferRemaining,
      this.tips,
      this.tips2,
      this.type,
      this.isTransfer});

  OrderDetailData.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    isCheck = json['is_check'];
    companyTitle = json['company_title'];
    statusStr = json['status_str'];
    status = json['status'];
    paymentType = json['payment_type'];
    payStatus = json['pay_status'];
    paidAmount = json['paid_amount'];
    payableAmount = json['payable_amount'];
    totalAmount = json['total_amount'];
    integral = json['integral'];
    trackingNumber = json['tracking_number'];
    createdAt = json['created_at'];
    remainingTime = json['remaining_time'];
    companyCode = json['company_code'];
    orderSn = json['order_sn'];
    pickType = json['pick_type'];
    voucherCode = json['voucher_code'];
    writeoffUrl = json['writeoff_url'];
    transferRemaining = json['transfer_remaining'];
    tips = json['tips'];
    tips2 = json['tips2'];
    type = json['type'];
    isTransfer = json['is_transfer'];
    if (json['products'] != null) {
      products = <OrderProductsItem>[];
      json['products'].forEach((v) {
        products!.add(new OrderProductsItem.fromJson(v));
      });
    }
    if (pickType == 1) {
      address = null;
    } else {
      address = json['address'] != null ? new CommonAddressItem.fromJson(json['address']) : null;
    }    
    if (json['costs'] != null) {
      costs = <CommonCostsVo>[];
      json['costs'].forEach((v) {
        costs!.add(new CommonCostsVo.fromJson(v));
      });
    }
    if (json['transfer'] != null) {
      transfer = <Transfer>[];
      json['transfer'].forEach((v) {
        transfer!.add(new Transfer.fromJson(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    data['is_check'] = this.isCheck;
    data['status_str'] = this.statusStr;
    data['company_title'] = this.companyTitle;
    data['order_sn'] = this.orderSn;
    data['status'] = this.status;
    data['payment_type'] = this.paymentType;
    data['pay_status'] = this.payStatus;
    data['paid_amount'] = this.paidAmount;
    data['payable_amount'] = this.payableAmount;
    data['total_amount'] = this.totalAmount;
    data['integral'] = this.integral;
    data['tracking_number'] = this.trackingNumber;
    data['created_at'] = this.createdAt;
    data['remaining_time'] = this.remainingTime;
    data['company_code'] = this.companyCode;
    data['pick_type'] = this.pickType;
    data['voucher_code'] = this.voucherCode;
    data['writeoff_url'] = this.writeoffUrl;
    data['transfer_remaining'] = this.transferRemaining;
    data['tips'] = this.tips;
    data['tips2'] = this.tips2;
    data['type'] = this.type;
    data['is_transfer'] = this.isTransfer;
    if (this.products != null) {
      data['products'] = this.products!.map((v) => v.toJson()).toList();
    }
    if (this.address != null) {
      data['address'] = this.address!.toJson();
    }
    if (this.costs != null) {
      data['costs'] = this.costs!.map((v) => v.toJson()).toList();
    }
    if (this.transfer != null) {
      data['transfer'] = this.transfer!.map((v) => v.toJson()).toList();
    }
    return data;
  }
}

class OrderProductsItem {
  int? productId;
  String? title;
  String? image;
  String? price;
  int? quantity;
  int? skuId;
  String? specIds;
  String? specStr;

  OrderProductsItem(
      {this.productId,
      this.title,
      this.image,
      this.price,
      this.quantity,
      this.skuId,
      this.specIds,
      this.specStr});

  OrderProductsItem.fromJson(Map<String, dynamic> json) {
    productId = json['product_id'];
    title = json['title'];
    image = json['image'];
    price = json['price'];
    quantity = json['quantity'];
    skuId = json['sku_id'];
    specIds = json['spec_ids'];
    specStr = json['spec_str'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['product_id'] = this.productId;
    data['title'] = this.title;
    data['image'] = this.image;
    data['price'] = this.price;
    data['quantity'] = this.quantity;
    data['sku_id'] = this.skuId;
    data['spec_ids'] = this.specIds;
    data['spec_str'] = this.specStr;
    return data;
  }
}

class Transfer {
  String? key;
  String? label;
  String? value;

  Transfer({this.key, this.label, this.value});

  Transfer.fromJson(Map<String, dynamic> json) {
    key = json['key'];
    label = json['label'];
    value = json['value'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['key'] = this.key;
    data['label'] = this.label;
    data['value'] = this.value;
    return data;
  }
}